<template>
  <div
    class="top scenetop"
    v-loading="loading"
    element-loading-text="拼命加载中"
    element-loading-spinner="el-icon-loading"
    element-loading-background="rgba(0, 0, 0, 0.8)"
  >
    <div class="buttonclient">
      <div class="clientside">
        <el-button :type="success" @click="clientside()">横屏模式</el-button>
      </div>
      <div class="clientside">
        <el-button :type="info" @click="mobileclient()">竖屏模式</el-button>
      </div>
    </div>
    <div class="buttonclienttext"><span>点击选择场景</span></div>
    <el-scrollbar>
      <div class="blocks">
        <div v-for="item in list" :key="item.id">
          <div v-if="item.sizeType === 1">
            <el-image
              :class="backid === item.id ? 'blockhover' : 'block'"
              @click="backgrounds(item, item.id)"
              fit="contain"
              :src="url + item.path"
              ><div slot="placeholder" class="image-slot">
                加载中
                <div class="loader"></div></div
            ></el-image>
            <br />
            <span class="demonstration">{{ item.name }}</span>
          </div>
          <div class="blockasflex" v-if="item.sizeType === 2">
            <div class="width:100%">
              <el-image
                :class="backid === item.id ? 'blockshover' : 'blockas'"
                @click="backgrounds(item, item.id)"
                fit="contain"
                :src="url + item.path"
                ><div slot="placeholder" class="image-slot">
                  加载中
                  <div class="loader"></div></div
              ></el-image>
              <br />
              <span class="demonstration">{{ item.name }}</span>
            </div>
          </div>
        </div>
      </div>
    </el-scrollbar>
  </div>
</template>

<script>
import { virtuallist } from "@/api/virtualhuman"; //场景
export default {
  props: ["flagscene"],
  name: "scene",
  data() {
    return {
      success: "primary",
      info: "info",
      list: "",
      url: this.$store.getters["url/urls"],
      falag: true,
      backid: null,
      loading: false,
    };
  },
  watch: {
    flagscene(val) {
      if (val === 1) {
        this.success = "primary";
        this.info = "info";
        virtuallist({
          pageIndex: 1,
          pageSize: 2000,
          type: 2,
          sizeType: 1,
        }).then((res) => {
          this.list = res.data.list;
        });
      } else {
        this.success = "info";
        this.info = "primary";
        virtuallist({
          pageIndex: 1,
          pageSize: 2000,
          type: 2,
          sizeType: 2,
        }).then((res) => {
          this.list = res.data.list;
        });
      }
    },
  },
  mounted() {},
  updated() {
    // this.virtuallistList();
    // console.log(this.falag);
    this.$nextTick(() => {
      // DOM 现在更新了
      this.falag = this.$store.getters["virtualhuman/getdistinguishability"];
    });
  },
  methods: {
    //场景函数
    virtuallistList() {
      this.loading = true;
      virtuallist({
        pageIndex: 1,
        pageSize: 200,
        type: 2,
        sizeType: 1,
      }).then((res) => {
        if (res.code === 200) {
          this.list = res.data.list;
          this.loading = false;
        } else {
          this.$message.error(res.msg);
          this.loading = false;
        }
      });
    },
    backgrounds(val, id) {
      this.$emit("backgroun", val);
      this.backid = id;
    },
    clientside() {
      //客户端
      this.loading = true;
      virtuallist({
        pageIndex: 1,
        pageSize: 100,
        type: 2,
        sizeType: 1,
      }).then((res) => {
        if (res.code === 200) {
          this.list = res.data.list;
          this.$emit("clientside");
          this.success = "primary";
          this.info = "info";
          this.loading = false;
        } else {
          this.$message.error(res.msg);
          this.loading = false;
        }
      });
    },
    mobileclient() {
      //手机端
      this.loading = true;
      virtuallist({
        pageIndex: 1,
        pageSize: 100,
        type: 2,
        sizeType: 2,
      }).then((res) => {
        if (res.code === 200) {
          this.list = res.data.list;
          this.$emit("mobileclient");
          this.success = "info";
          this.info = "primary";
          this.loading = false;
        } else {
          this.$message.error(res.msg);
          this.loading = false;
        }
      });
    },
  },
};
</script>

<style lang="scss" scoped>
.buttonclienttext {
  color: rgb(168, 168, 168);
  margin-top: 10px;
  font-size: 14px;
}
.top {
  background-color: #222;
  width: 100%;
  height: 100%;
  .buttonclient {
    width: 100%;
    display: flex;
    justify-content: space-around;
    .clientside {
      width: 45%;
      .el-button {
        width: 100%;
      }
    }
  }
  .blocks {
    box-sizing: border-box;
    padding: 0 10px;
    height: 750px;
    width: 100%;
    display: flex;
    justify-content: space-between;
    flex-wrap: wrap;
    .block {
      box-sizing: border-box;
      border-radius: 5%;
      margin: 10px auto 0;
      width: 70%;
      border: 1px solid #757575;
      &:hover {
        border: 1px solid #409eff;
      }
    }
    .blockhover {
      box-sizing: border-box;
      border-radius: 5%;
      margin: 10px auto 0;
      width: 70%;
      border: 3px solid #409eff;
    }
    .blockasflex {
      max-width: 110px;
      .blockas {
        box-sizing: border-box;
        border-radius: 5%;
        margin-top: 10px;
        border: 1px solid #757575;
        &:hover {
          border: 1px solid #409eff;
        }
      }
      .blockshover {
        box-sizing: border-box;
        border-radius: 5%;
        margin-top: 10px;
        border: 1px solid #409eff;
        box-shadow: 0px 0px 3px 3px #409eff;
      }
    }
  }
  .demonstration {
    color: #fff;
  }
}
.block .el-button {
  padding: 0 !important;
  border: 0;
}
</style>
<style lang="scss" scoped>
html,
body {
  height: 100%;
}

body {
  align-items: center;
  // background-color: #1D1F20;
  display: flex;
  justify-content: center;
}

.loader {
  animation: rotate 1s infinite;
  height: 50px;
  width: 50px;
}

.loader:before,
.loader:after {
  border-radius: 50%;
  content: "";
  display: block;
  height: 20px;
  width: 20px;
}
.loader:before {
  animation: ball1 1s infinite;
  background-color: #cb2025;
  box-shadow: 30px 0 0 #f8b334;
  margin-bottom: 10px;
}
.loader:after {
  animation: ball2 1s infinite;
  background-color: #00a096;
  box-shadow: 30px 0 0 #97bf0d;
}

@keyframes rotate {
  0% {
    -webkit-transform: rotate(0deg) scale(0.8);
    -moz-transform: rotate(0deg) scale(0.8);
  }
  50% {
    -webkit-transform: rotate(360deg) scale(1.2);
    -moz-transform: rotate(360deg) scale(1.2);
  }
  100% {
    -webkit-transform: rotate(720deg) scale(0.8);
    -moz-transform: rotate(720deg) scale(0.8);
  }
}

@keyframes ball1 {
  0% {
    box-shadow: 30px 0 0 #f8b334;
  }
  50% {
    box-shadow: 0 0 0 #f8b334;
    margin-bottom: 0;
    -webkit-transform: translate(15px, 15px);
    -moz-transform: translate(15px, 15px);
  }
  100% {
    box-shadow: 30px 0 0 #f8b334;
    margin-bottom: 10px;
  }
}

@keyframes ball2 {
  0% {
    box-shadow: 30px 0 0 #97bf0d;
  }
  50% {
    box-shadow: 0 0 0 #97bf0d;
    margin-top: -20px;
    -webkit-transform: translate(15px, 15px);
    -moz-transform: translate(15px, 15px);
  }
  100% {
    box-shadow: 30px 0 0 #97bf0d;
    margin-top: 0;
  }
}
</style>